package com.zhu.classfile.constant;

public enum  ConstantTag {
    CONSTANT_Class(7),
    CONSTANT_Fieldref(9),
    CONSTANT_Methodref(10),
    CONSTANT_InterfaceMethodref(11),
    CONSTANT_String(8),
    CONSTANT_Integer(3),
    CONSTANT_Float(4),
    CONSTANT_Long(5),
    CONSTANT_Double(6),
    CONSTANT_NameAndType(12),
    CONSTANT_Utf8(1),
    CONSTANT_MethodHandle(15),
    CONSTANT_MethodType(16),
    CONSTANT_InvokeDynamic(18);

    private final int tag;

    ConstantTag(int tag) {
        this.tag = tag;
    }

    public int getTagVal() {
        return tag;
    }

    // 根据 tag 值获取对应的 ConstantTag 枚举实例
    public static ConstantTag fromTag(int tag) {
        for (ConstantTag constantTag : values()) {
            if (constantTag.getTagVal() == tag) {
                return constantTag;
            }
        }
        throw new IllegalArgumentException("Invalid constant tag: " + tag);
    }
}
